#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    long long numberOfWays(string s) {
        long long zero = 0, one = 0, ret = 0, n = s.size();
        vector<pair<long, long>> arr(n);
        for (int i = n - 1; i >= 0; i--)
            if (s[i] == '0')
                zero++, arr[i].second = one;
            else
                one++, arr[i].second = zero;
        zero = one = 0;
        for (int i = 0; i < n; i++)
            if (s[i] == '0')
                zero++, arr[i].first = one;
            else
                one++, arr[i].first = zero;

        for (int i = 0; i < n; i++)
            ret += arr[i].first * arr[i].second;
        return ret;
    }
};